<template>
  <el-form ref="postForm" :model="postForm" label-position="right" label-width="100px" class="account-form">
    <el-row :gutter="20">
      <el-col :span="18" :offset="4">
        <el-form-item label="管理员" prop="state">
          <el-switch v-model="postForm.state" :active-value="1" :inactive-value="0" @change="setAdmin" />
          <div class="form-tips text-warning">管理人员可以在微信端管理签到礼</div>
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
</template>

<script>
import {
  setAdmin
} from '@/api/wechatAccounts'

const defaultForm = {
  id: undefined,
  state: ''
}

export default {
  name: 'WechatAccountForm',
  props: {
    accountId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      postForm: Object.assign({}, defaultForm)
    }
  },
  created() {
    this.postForm.id = this.accountId
  },
  methods: {
    setAdmin() {
      setAdmin(this.postForm).then(response => {
        // console.log(response)
        this.$notify({
          title: '成功',
          message: '设置管理员成功',
          type: 'success',
          duration: 2000
        })
      }).catch(err => {
        console.log(err)
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.container {
  padding: 40px 0;
}
.account-form {
  margin-top: 60px;
}
</style>
